package site.lisl.mynote.algorithm.queue;

/**
 * @author Administrator
 */
public class LinkQueue<T> {
    private Integer size = 0;
    // 队列的队首和队尾
    private Node<T> head = null;
    private Node<T> tail = null;


    public boolean enQueue(T obj){
        if(tail == null){
            Node newNode = new Node<>(obj,null);
            tail = newNode;
            head = newNode;
        }else{
            tail.next = new Node(obj,null);
            tail = tail.next;
        }
        size++;
        return true;
    }

    public T deQueue(){
        if(head == null){
            return null;
        }
        T value = head.value;
        head = head.next;
        if(head == null){
            tail = null;
        }
        size--;
        return value;
    }

    public Integer getSize(){
        return this.size;
    }

    class Node<T>{
        private T value;
        private Node next;

        public Node(T value,Node next){
            this.value = value;
            this.next = next;
        }


    }

}
